#include <memory>
#include <iostream>
#include <verilated.h>
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>
#include <iostream>
#include <verilated_vcd_c.h>
#include "Vmycpu.h"
#include "Vmycpu___024root.h"


#define MAXCYCLE 1000

// mycpu运行一个周期
void next_cycle(std::shared_ptr<Vmycpu> mycpu){
  mycpu->eval();
  mycpu->clk = 0;
  mycpu->eval();
  mycpu->clk = 1;
  mycpu->eval();
}

int main(int argc, char **argv) {

  std::shared_ptr<Vmycpu> mycpu = std::make_shared<Vmycpu>();

  // wave
    Verilated::traceEverOn(true);
    VerilatedVcdC *m_trace = new VerilatedVcdC;  
    mycpu->trace(m_trace, 5);               
    m_trace->open("waveform.vcd");

  // initial
  mycpu->rst_n = 0;
  next_cycle(mycpu);
  mycpu->rst_n = 1;
  m_trace->dump(0);
  
  for (int i = 1; i < MAXCYCLE; i++) {
    next_cycle(mycpu);
    m_trace->dump(i);
    if(mycpu->done == 1){
      printf(" Test Over\n");
      break;
    }
  }
 
  exit(EXIT_SUCCESS);

}
